home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
START Magazine
/
START VOL 3 NO 5.st
/
GENINPUT.ARC
/
LISTING2.LST
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
File List
|
1988-09-20
|
38.3 KB
|
1,292 lines
' =============================================================================
' LISTING 2 GENERALIZED INPUT ROUTINES
' BY MICHAEL HEPNER
' COPYRIGHT 1988 ANTIC PUBLISHING
' =============================================================================
'
Fullw 1
Titlew 1," Generalized Input Routines "
Cls
'
' -----------------------------------------------------------------------------
' CHECK SCREEN RESOLUTION: Must run in MEDIUM or HIGH resolution.
' -----------------------------------------------------------------------------
Rez%=Xbios(4)
If Rez%=0 Then
Alert 3," Please switch to | | MEDIUM RESOLUTION ",1," OK ",B
Quit
Endif
'
' -----------------------------------------------------------------------------
' INITIALIZE: Dimension Arrays and call the Generalized Init. Routines
' -----------------------------------------------------------------------------
Max_recs%=90
Dim Friend$(90),Street$(90),City$(90),State$(90),Zip$(90),Phone$(90)
'
Gosub Menu_setup
Gosub Fld_dimen
'
' -----------------------------------------------------------------------------
' SHOW LIST OF OPTIONS AVAILABLE:
' When selected option is done, show the list again.
' -----------------------------------------------------------------------------
Do
Gosub Show_main_option_list
Loop
'
' ---------------------------- END OF MAIN PROGRAM --------------------------
'
'
' =============================================================================
' SHOW_MAIN_OPTION_LIST: This procedure shows how to initialize the DATA
' values and call the Generalized Option List Procedure.
' -----------------------------------------------------------------------------
Procedure Show_main_option_list
Titlew 1," Generalized Input Routines "
'
Restore Main_list_menu_data ! Build the customized
Gosub Build_menu_bar ! drop down menus.
'
Repeat
Restore Main_option_list_data ! Build the customized
Gosub Show_option_list ! option list.
'
Gosub Check_which_option ! Wait for MOUSE or Func-key.
Until Function%>0
'
On Function% Gosub Option1,Option2,Option3
Return
'
'
' =============================================================================
' ========== OPTION 1 - CREATE NEW RECORDS ==========
' =============================================================================
Procedure Option1
Titlew 1," Create New Records "
Cls
'
Restore Opt1_menu_data ! Different
Gosub Build_menu_bar ! drop down menus.
'
Restore Opt1_fld_data ! Set up the
Gosub Fld_setup ! data entry screen.
'
Opt_done%=0
While Opt_done%=0 And Num_recs%<Max_recs%
Gosub Create_rec
Wend
'
If Num_recs%>=Max_recs% Then
Alert 3," Maximum Number | of records has | been reached. ",1," OK ",B
Endif
Return
'
' =============================================================================
' CREATE_REC: Initialize all fields to spaces. Call REC_INPUT to do the work.
' -----------------------------------------------------------------------------
Procedure Create_rec
Inc Num_recs%
Rec_num%=Num_recs%
'
For I%=1 To Num_flds%
Fld_val$(I%)=Space$(Fld_leng%(I%))
Next I%
'
Gosub Rec_input
'
If Rec_done%=99 Then
Dec Num_recs%
Endif
Return
'
' =============================================================================
' REC_INPUT: This procedure processes the data entry screen.
' -----------------------------------------------------------------------------
Procedure Rec_input
Redraw%=1
'
Rec_done%=0
'
Repeat
If Redraw%=1 Then ! First time or after desk
Gosub Show_headings ! accessory, display screen.
Endif
'
Gosub Ask_for_field ! Input the field.
Fld_num%=Nxt_fld% ! Next field selected.
'
If Rec_done%=1 Then
Xsub%=1
For Fld_num%=1 To Num_flds%
Gosub Validate_field
Exit If Rec_done%=0
Next Fld_num%
Endif
Until Rec_done%>0 ! Loop thru all fields.
'
If Rec_done%=1 Then
Friend$(Rec_num%)=Fld_val$(1)
Street$(Rec_num%)=Fld_val$(2)
City$(Rec_num%)=Fld_val$(3)
State$(Rec_num%)=Fld_val$(4)
Zip$(Rec_num%)=Fld_val$(5)
Phone$(Rec_num%)=Fld_val$(6)
Endif
Return
'
' =============================================================================
' SUBROUTINES FOR FIELD EDITS
' =============================================================================
Procedure Ask_for_field
Temp$=Fld_val$(Fld_num%)
Gosub Check_field_input
Fld_val$(Fld_num%)=Temp$
'
Gosub Clear_box
'
If Fld_done%=1 Then
Gosub Validate_field
Endif
Return
'
'
' =============================================================================
' VALIDATE_FIELD: For those fields that need edits, call the edit procedure.
' -----------------------------------------------------------------------------
Procedure Validate_field
On Fld_num% Gosub Edit_name,Edit_street,No_edit,No_edit,No_edit,Edit_phone
Return
'
' =============================================================================
Procedure Edit_name
If Fld_val$(1)=Space$(Fld_leng%(1)) Then
Print At(24,19);"Friend's name may not be blank."
Fld_done%=0
Nxt_fld%=Fld_num%
Rec_done%=0
Endif
Return
'
' =============================================================================
Procedure Edit_street
If Fld_val$(2)=Space$(Fld_leng%(2)) Then
Print At(23,19);"Friend's street may not be blank."
Fld_done%=0
Nxt_fld%=Fld_num%
Rec_done%=0
Endif
Return
'
' =============================================================================
Procedure Edit_phone
If Fld_val$(6)=Space$(Fld_leng%(6)) Then
Print At(24,19);"Friend's phone may not be blank."
Fld_done%=0
Nxt_fld%=Fld_num%
Rec_done%=0
Endif
Return
'
' =============================================================================
Procedure No_edit
Return
'
'
' =============================================================================
' ========== OPTION 2 - LIST/EDIT/DELETE RECORDS ==========
' =============================================================================
Procedure Option2
Titlew 1," List/Edit/Delete Records "
Cls
'
Restore Opt2_menu_data ! Different
Gosub Build_menu_bar ! drop down menus.
'
Restore Opt1_fld_data ! Uses the same
Gosub Fld_setup ! field definitions.
'
Opt_done%=0
Repeat
Gosub List_records
Until Opt_done%>0
Return
'
' =============================================================================
' LIST_RECORDS: Build headers for the list screen.
' -----------------------------------------------------------------------------
Procedure List_records
Cls
Print At(25,2);Num_recs%;" record(s) have been entered."
'
If Num_recs%>0 Then
Print At(6,4);"# ";Fld_heading$(1)
Print At(6,5);"-- ";String$(Fld_leng%(1),"-")
X%=Fld_leng%(1)+12
Print At(X%,4);Fld_heading$(2)
Print At(X%,5);String$(Fld_leng%(2),"-")
X%=X%+2+Fld_leng%(2)
Print At(X%,4);Fld_heading$(6)
Print At(X%,5);String$(Fld_leng%(6),"-")
'
Show_prev%=0
Gosub List_15_recs
Gosub Highlight
Endif
'
Rec_done%=0
Repeat
Gosub Check_which_record
Until Rec_done%>0 Or Redraw%=1
Return
'
'
' =============================================================================
' LIST_15_RECS: List 15 records to the screen.
' -----------------------------------------------------------------------------
Procedure List_15_recs
Deffill 0,1
Pbox 24,39*Rez%,614,176*Rez%
'
Show_limit%=Min(15,Num_recs%-Show_prev%)
'
For I%=1 To Show_limit%
S%=Show_prev%+I%
Print At(6,5+I%);S%;"."
Print At(10,5+I%);Friend$(S%);" ";Street$(S%);" ";Phone$(S%)
Next I%
'
Show_num%=1
'
If (Show_prev%+Show_limit%)<Num_recs% Then
Deftext 3,0,0,Txt_size%
Text 96,172*Rez%,"More"
Deftext 1,0,0,Txt_size%
Color 2
Defline 1,1,0,0
Box 64,164*Rez%,160,174*Rez%
Endif
'
If Show_prev%>0 Then
Deftext 3,0,0,Txt_size%
Text 480,172*Rez%,"Start over"
Deftext 1,0,0,Txt_size%
Color 2
Defline 1,1,0,0
Box 464,164*Rez%,576,174*Rez%
Endif
Return
'
'
' =============================================================================
' HIGHLIGHT: Show one record in inverse video.
' -----------------------------------------------------------------------------
Procedure Highlight
Graphmode 3
Deffill 1,1
Yline%=(39+8*Show_num%)*Rez%
Pbox 34,Yline%+2*Rez%,603,Yline%-7*Rez%
Graphmode 1
Return
'
'
' ==============================================================================
' EDIT_RECORD: Edit an existing record. Call REC_INPUT to do the work.
' -----------------------------------------------------------------------------
Procedure Edit_record
If Num_recs%>0 Then
Rec_num%=Show_num%+Show_prev%
Fld_val$(1)=Friend$(Rec_num%)
Fld_val$(2)=Street$(Rec_num%)
Fld_val$(3)=City$(Rec_num%)
Fld_val$(4)=State$(Rec_num%)
Fld_val$(5)=Zip$(Rec_num%)
Fld_val$(6)=Phone$(Rec_num%)
Gosub Rec_input
Endif
Return
'
'
' =============================================================================
' DELETE_RECORD: Remove the record from the table.
' -----------------------------------------------------------------------------
Procedure Delete_record
If Num_recs%>0 Then
Rec_num%=Show_num%+Show_prev%
Alert 2,"Delete the|highlighted|record",1," yes | no ",B
If B=1 Then
Gosub Shift_records_down
Endif
Endif
Return
'
'
' =============================================================================
' SHIFT_RECORDS_DOWN: To replace the deleted record.
' -----------------------------------------------------------------------------
Procedure Shift_records_down
If Rec_num%<Num_recs% Then
For I%=Rec_num% To Num_recs%-1
Friend$(I%)=Friend$(I%+1)
Street$(I%)=Street$(I%+1)
City$(I%)=City$(I%+1)
State$(I%)=State$(I%+1)
Zip$(I%)=Zip$(I%+1)
Phone$(I%)=Phone$(I%+1)
Next I%
Endif
Dec Num_recs%
Rec_done%=1
Return
'
'
' =============================================================================
' ========== OPTION 3 - EXIT ==========
' =============================================================================
Procedure Option3
Alert 2," Do you really | | want to QUIT? ",1,"YES|NO ",B
If B=1 Then
@Restorepal
Edit
Endif
Return
'
'
' =============================================================================
' ROUTINES TO LOAD AND SAVE THE DATA FILES
' =============================================================================
Procedure Load_file
Print At(6,2);"LOAD FILE"
Fileselect "\*.FIL","",Lfile$
If Len(Lfile$)>0 Then
Open "R",#1,Lfile$,99
Field #1,25 As Rec_name$,25 As Rec_street$,20 As Rec_city$,12 As Rec_state$,5 As Rec_zip$,12 As Rec_phone$
For I%=1 To Max_recs%
Get #1,I%
Friend$(I%)=Rec_name$
Street$(I%)=Rec_street$
City$(I%)=Rec_city$
State$(I%)=Rec_state$
Zip$(I%)=Rec_zip$
Phone$(I%)=Rec_phone$
Num_recs%=I%
Exit If Eof(#1)
Next I%
Close #1
Endif
Print At(6,2);" "
Return
'
' =============================================================================
Procedure Save_file
If Num_recs%>0 Then
Print At(6,2);"SAVE FILE"
Fileselect "\*.FIL","",Sfile$
If Len(Sfile$)>0 Then
If Exist(Sfile$)=-1 Then
Kill Sfile$
Endif
Open "R",#1,Sfile$,99
Field #1,25 As Rec_name$,25 As Rec_street$,20 As Rec_city$,12 As Rec_state$,5 As Rec_zip$,12 As Rec_phone$
For I%=1 To Num_recs%
Lset Rec_name$=Friend$(I%)
Lset Rec_street$=Street$(I%)
Lset Rec_city$=City$(I%)
Lset Rec_state$=State$(I%)
Lset Rec_zip$=Zip$(I%)
Lset Rec_phone$=Phone$(I%)
Put #1,I%
Next I%
Close #1
Endif
Print At(6,2);" "
Endif
Return
'
'
' =============================================================================
' GENERALIZED INPUT ROUTINES TO PROCESS THE MENU BAR
' =============================================================================
'
' -----------------------------------------------------------------------------
' MENU_SETUP: Dimension the Menu Bar Array, initialize variables,
' and set the screen colors and text size.
' -----------------------------------------------------------------------------
Procedure Menu_setup
Max_menu%=150
Dim Menu_bar$(Max_menu%)
Dim Spalette%(16,3)
'
@Save_pal
Insert_mode%=0
First_redraw%=0
Redraw%=0
'
If Rez%=1 Then
Setcolor 0,7,7,7
Setcolor 1,7,0,0
Setcolor 2,0,0,4
Setcolor 3,0,0,0
Txt_size%=6
Else
Setcolor 0,7,7,7
Setcolor 1,0,0,0
Txt_size%=13
Endif
Return
'
'
' ==============================================================================
' BUILD_MENU_BAR: Builds the drop down menus and activates them.
' -----------------------------------------------------------------------------
Procedure Build_menu_bar
For I%=0 To Max_menu%
Read Menu_bar$(I%)
Exit If Menu_bar$(I%)="***"
Next I%
'
Menu_bar$(I%)=""
Menu Menu_bar$()
On Menu Gosub Menu_handler
On Menu Message Gosub Menu_message
Return
'
' -----------------------------------------------------------------------------
' DATA for MENU BAR: First line is needed to activate the desk accessories.
' On other lines, the first value will appear on the menu bar and the
' following values will appear on the drop down menu.
' -----------------------------------------------------------------------------
Main_list_menu_data:
Data DESK, About Gen. Input ,------------------,1,2,3,4,5,6,""
Data QUIT, End Program,""
Data FILE, Load File, Save File,""
Data ***
'
Opt1_menu_data:
Data DESK, About Gen. Input ,------------------,1,2,3,4,5,6,""
Data QUIT, End Program,""
Data DONE, Return to Menu,""
Data CANCEL, Start New Record, Return to Menu,""
Data ***
'
Opt2_menu_data:
Data DESK, About Gen. Input ,------------------,1,2,3,4,5,6,""
Data QUIT, End Program,""
Data DONE, Return to Menu,""
Data UPDATE, Edit Record, Delete Record,""
Data ***
'
'
' =============================================================================
' MENU_HANDLER: Determines which drop down menu option was selected.
' -----------------------------------------------------------------------------
Procedure Menu_handler
Menu Off
Menu_option$=Menu_bar$(Menu(0))
'
If Menu_option$=" Start New Record" Then
Fld_done%=99
Rec_done%=99
Endif
'
If Menu_option$=" Return to Menu" Then
Fld_done%=99
Rec_done%=99
Opt_done%=99
Endif
'
If Menu_option$=" Load File" Then
Gosub Load_file
Endif
'
If Menu_option$=" Save File" Then
Gosub Save_file
Endif
'
If Menu_option$=" Edit Record" Then
M0%=Menu(0)
Menu M0%,2
Menu M0%+1,2
Gosub Edit_record
Menu M0%,3
Menu M0%+1,3
Endif
'
If Menu_option$=" Delete Record" Then
Gosub Delete_record
Endif
'
If Menu_option$=" End Program" Then
Gosub Option3
Endif
'
If Menu_option$=" About Gen. Input " Then
A1$="Generalized Input Routines|"
A2$=" Sample -- Listing 2|"
A3$=" by Michael Hepner|"
A4$=" "+Chr$(189)+" 1988 Antic Publishing"
Alert 1,A1$+A2$+A3$+A4$,1,"OK",A
Endif
Return
'
'
' =============================================================================
' MENU_MESSAGE: Determine if the screen needs to be redrawn.
' (Ignore first call which comes at the start of the program.)
' -----------------------------------------------------------------------------
Procedure Menu_message
If Menu(1)=20 Then
If First_redraw%=0 Then
First_redraw%=1
Else
Redraw%=1
Endif
'
If Rez%=1 Then
Setcolor 0,7,7,7
Setcolor 1,7,0,0
Setcolor 2,0,0,4
Setcolor 3,0,0,0
Else
Setcolor 0,7,7,7
Setcolor 1,0,0,0
Endif
Endif
Return
'
'
' =============================================================================
' GENERALIZED ROUTINES TO PROCESS THE OPTION LIST
' =============================================================================
'
' -----------------------------------------------------------------------------
' SHOW_OPTION_LIST: Using DATA statements, build the list of options.
' Before calling this procedure, use a RESTORE command to point to
' the DATA statements for the option list.
' -----------------------------------------------------------------------------
Procedure Show_option_list
Cls
Color 2
Defline 1,1,0,0
'
Read Offset%,Spacing%
Offset%=Offset%*Rez%
Spacing%=Spacing%*Rez%
'
Read Num_select%
For I%=1 To Num_select%
Read Select$
Y%=Spacing%*(I%-1)+Offset%
Deftext 2,0,0,Txt_size%
Text 192,Y%-Rez%,"F"
Text 200,Y%-Rez%,I%
Rbox 180,Y%-9*Rez%,221,Y%+Rez%
Deftext 1,0,0,Txt_size%
Text 248,Y%-Rez%,Select$
Next I%
'
Gosub Build_box
Text 160,152*Rez%,"Press function key of desired option,"
Text 304,160*Rez%,"or"
Text 160,168*Rez%,"click the MOUSE on the desired option."
Return
'
' -----------------------------------------------------------------------------
' DATA for OPTION LIST: Options are listed using the TEXT command.
' First data value gives the Y coordinate for the first option.
' Second value gives the text spacing between options.
' Third value is the number of options followed by their text values.
' -----------------------------------------------------------------------------
Main_option_list_data:
Data 48,22
Data 3
Data Create New Records
Data List/Edit/Delete Records
Data Quit
'
'
' =============================================================================
' CHECK_WHICH_OPTION: Processes user inputs from the Option Screen.
' -----------------------------------------------------------------------------
Procedure Check_which_option
On Menu Key Gosub Check_function_key
On Menu Button 1,1,1 Gosub Compute_mouse_option
'
Function%=0
Redraw%=0
Repeat
On Menu
Until (Function%>0 And Function%<=Num_select%) Or Redraw%=1
Return
'
'
' =============================================================================
' CHECK_FUNCTION_KEY: Only responds if function key matches an option.
' -----------------------------------------------------------------------------
Procedure Check_function_key
If (Menu(14) And 255)=0 Then
Key%=Menu(14)/256
If Key%>58 And Key%<=58+Num_select% Then
Function%=Key%-58
Endif
Endif
Return
'
'
' =============================================================================
' COMPUTE_MOUSE_OPTION: Only responds if MOUSE was clicked on an option.
' -----------------------------------------------------------------------------
Procedure Compute_mouse_option
Y%=Menu(11)-22*Rez%
Y1%=Y%-Offset%+9*Rez%
Y2%=Int(Y1%/Spacing%)
Y3%=Y1%-Y2%*Spacing%
If Y3%>=0 And Y3%<=10*Rez% Then
Function%=Y2%+1
Endif
Return
'
'
' =============================================================================
' GENERALIZED ROUTINES FOR DEFINING THE INPUT FIELDS AND SCREEN LAYOUT
' =============================================================================
'
' -----------------------------------------------------------------------------
' FLD_DIMEN: Dimension the Field Arrays (large enough for the largest set).
' -----------------------------------------------------------------------------
Procedure Fld_dimen
Max_flds%=6
Dim Fld_hstart%(Max_flds%),Fld_yline%(Max_flds%),Fld_xstart%(Max_flds%)
Dim Fld_leng%(Max_flds%),Fld_type$(Max_flds%),Fld_heading$(Max_flds%)
Dim Fld_prompt$(Max_flds%),Fld_help$(Max_flds%)
Dim Fld_val$(Max_flds%)
Return
'
'
' =============================================================================
' FLD_SETUP: For each different screen, read the DATA statements that define
' each field on the screen, and build the screen definition arrays.
' -----------------------------------------------------------------------------
Procedure Fld_setup
Read Num_flds%
For I%=1 To Num_flds%
Read Fld_hstart%(I%),Fld_yline%(I%),Fld_xstart%(I%)
Read Fld_leng%(I%),Fld_type$(I%),Fld_heading$(I%)
Read Fld_prompt$(I%),Fld_help$(I%)
Next I%
Return
'
' -----------------------------------------------------------------------------
' DATA for SCREEN SETUP: First data value tells how many sets of data follow.
' Each set contains four numeric values and four text values:
' Y coordinate, X coordinate of header, X coordinate of field,
' length, type, heading, prompt, and help message.
' -----------------------------------------------------------------------------
Opt1_fld_data:
Data 6
'
Data 120,40,168,25,A-Z,Name
Data "Enter friend's name."
Data "Friend's name is required. It must be alphabetic."
'
Data 184,56,248,25,ANY,Street
Data "Enter friend's street address."
Data "Friend's street address is required. All characters are valid."
'
Data 184,66,248,20,A-Z,City
Data "Enter city where friend lives."
Data "Friend's city is optional. Must be alphabetic."
'
Data 184,76,248,12,A-Z,State
Data "Enter state where friend lives."
Data "Friend's state is optional. Must be alphabetic."
'
Data 184,86,248,5,NUM,Zip
Data "Enter zip code for friend's address."
Data "Friend's zip is optional. Must be numeric."
'
Data 264,108,328,14,PHN,Phone
Data "Enter friend's phone number."
Data "Only numbers, blanks, dashes and parentheses allowed."
'
'
' =============================================================================
' SHOW_HEADINGS: Using the screen definition arrays, build the screen and
' build the instruction box at the bottom of the screen.
' -----------------------------------------------------------------------------
Procedure Show_headings
Cls
Defline 1,1,0,0
Color 2
Print At(2,2);"Record #: ";Rec_num%
For I%=1 To Num_flds%
Y%=Fld_yline%(I%)*Rez%
Text Fld_hstart%(I%),Y%,Fld_heading$(I%)
Text Fld_hstart%(I%)+8*Len(Fld_heading$(I%)),Y%,":"
X%=Fld_xstart%(I%)
Text X%,Y%,Fld_val$(I%)
Line X%,Y%+2,X%-1+8*Fld_leng%(I%),Y%+2
Next I%
'
Gosub Build_box
Box 4,125*Rez%,634,139*Rez%
Box 9,127*Rez%,629,137*Rez%
Deffill 2,1
Fill 7,126*Rez%
'
Deftext 3,0,0,Txt_size%
Text 24,135*Rez%,"Press F10 when all fields are correct."
'
If Insert_mode%=0 Then
Deftext 2,0,0,Txt_size%
Text 488,135*Rez%,"Insert mode: Off"
Else
Deftext 3,0,0,Txt_size%
Text 488,135*Rez%,"Insert mode: ON "
Endif
Deftext 1,0,0,Txt_size%
'
Fld_num%=1
Xsub%=1
Return
'
'
' =============================================================================
' BUILD_BOX: Draws a box with thick border.
' -----------------------------------------------------------------------------
Procedure Build_box
Color 2
Defline 1,1,0,0
Box 4,137*Rez%,634,176*Rez%
Box 9,139*Rez%,629,174*Rez%
Deffill 2,1
Fill 7,138*Rez%
Return
'
'
' =============================================================================
' CLEAR_BOX: Erases the inside of the box.
' -----------------------------------------------------------------------------
Procedure Clear_box
Deffill 0,1
Pbox 48,144*Rez%,604,168*Rez%
Return
'
'
' =============================================================================
' ROUTINES TO MOVE THE HIGHLIGHT BAR IN OPTION TWO
' =============================================================================
'
' -----------------------------------------------------------------------------
' CHECK_WHICH_RECORD: Processes user inputs from the list screen in Option 2.
' -----------------------------------------------------------------------------
Procedure Check_which_record
On Menu Key Gosub Check_arrow_key
On Menu Button 1,1,1 Gosub Compute_mouse_record
'
Rec_done%=0
Redraw%=0
Repeat
On Menu
Until Rec_done%>0 Or Redraw%=1
Return
'
'
' =============================================================================
' CHECK_ARROW_KEY: Only responds if the Up Arrow or Down Arrow is pressed.
' -----------------------------------------------------------------------------
Procedure Check_arrow_key
If (Menu(14) And 255)=0 Then
Fkey=Menu(14)/256
If Fkey=72 Then ! Up Arrow
Nxt_rec%=Show_num%-1
Gosub Next_record
Else
If Fkey=80 Then ! Down Arrow
Nxt_rec%=Show_num%+1
Gosub Next_record
Endif
Endif
Endif
Return
'
'
' =============================================================================
' NEXT_RECORD: Determines if cursor must jump to top or bottom of list.
' -----------------------------------------------------------------------------
Procedure Next_record
Gosub Highlight
If Nxt_rec%<1 Then
Show_num%=Show_limit%
Else
If Nxt_rec%>Show_limit% Then
Show_num%=1
Else
Show_num%=Nxt_rec%
Endif
Endif
Gosub Highlight
Return
'
'
' =============================================================================
' COMPUTE_MOUSE_RECORD: Computes which record the MOUSE was clicked on.
' -----------------------------------------------------------------------------
Procedure Compute_mouse_record
X%=Menu(10)
Y%=Menu(11)-22*Rez%
Nxt_rec%=(Y%-32*Rez%)/(8*Rez%)
Gosub Highlight
'
If Y%>154 Then
If X%<160 And (Show_prev%+Show_limit%)<Num_recs% Then
Add Show_prev%,12
Gosub List_15_recs
Nxt_rec%=1
Else
If X%>464 And Show_prev%>0 Then
Show_prev%=0
Gosub List_15_recs
Nxt_rec%=1
Endif
Endif
Endif
'
If Nxt_rec%<1 Then
Show_num%=1
Else
If Nxt_rec%>Show_limit% Then
Show_num%=Show_limit%
Else
Show_num%=Nxt_rec%
Endif
Endif
Gosub Highlight
Return
'
'
' =============================================================================
' ROUTINES TO READ AN ENTIRE FIELD
' =============================================================================
'
' -----------------------------------------------------------------------------
' CHECK_FIELD_INPUT: Processes user inputs from a data entry screen.
' -----------------------------------------------------------------------------
Procedure Check_field_input
Hold$=Temp$
'
X%=Int((80-Len(Fld_prompt$(Fld_num%)))/2)
Print At(X%,20);Fld_prompt$(Fld_num%)
'
Xstart%=Fld_xstart%(Fld_num%)
Yline%=Fld_yline%(Fld_num%)*Rez%
Fleng%=Fld_leng%(Fld_num%)
Type_input$=Fld_type$(Fld_num%)
'
Gosub Cursor
'
On Menu Key Gosub Check_field_key
On Menu Button 1,1,1 Gosub Compute_mouse_field
'
Fld_done%=0
Redraw%=0
Repeat
On Menu
Until Fld_done%>0 Or Redraw%=1
Return
'
'
' =============================================================================
' CHECK_FIELD_KEY: Processes keyboard inputs from a data entry screen.
' -----------------------------------------------------------------------------
Procedure Check_field_key
Menu Off
If Menu(13)>=4 Then ! Skip Control & Alternate characters
Gosub Beep
Else
If (Menu(14) And 255)=0 Then
Gosub Check_special_key
Else
Gosub Check_regular_key
Endif
Endif
Return
'
'
' =============================================================================
' CHECK_REGULAR_KEY: Processes standard keys.
' -----------------------------------------------------------------------------
Procedure Check_regular_key
If Menu(14)=7181 Then ! Return
Gosub Finish_field
Else
If Menu(14)=3849 ! Tab
Gosub Finish_field
Else
If Menu(14)=29197 Then ! Enter
Gosub Finish_field
Else
If Menu(14)=3592 Then ! Backspace
Gosub Have_backspace
Else
If Menu(14)=21375 Then ! Delete
Gosub Have_delete
Else
If Menu(14)=283 Then ! Escape
Gosub Clear_field
Else
Gosub Have_data ! add character to field
Endif
Endif
Endif
Endif
Endif
Endif
Return
'
'
' =============================================================================
' CHECK_SPECIAL_KEY: Processes function keys and other special keys.
' (Only function key F10 is used by the sample data entry screen.)
' ( Fkey=59 for F1 ----> Fkey=67 for F9 )
' -----------------------------------------------------------------------------
Procedure Check_special_key
Fkey=Menu(14)/256
If Fkey=72 Then ! Up Arrow
Nxt_fld%=Fld_num%-1
Nxt_xsub%=1
Gosub Next_field
Else
If Fkey=80 Then ! Down Arrow
Nxt_fld%=Fld_num%+1
Nxt_xsub%=1
Gosub Next_field
Else
If Fkey=75 Then ! Left Arrow
Gosub Have_left_arrow
Else
If Fkey=77 Then ! Right Arrow
Gosub Have_right_arrow
Else
If Fkey=82 Then ! Insert
Gosub Have_insert
Else
If Fkey=71 Then ! Clr Home
Gosub Clear_field
Else
If Fkey=97 Then ! Undo
Gosub Have_undo_key
Else
If Fkey=98 Then ! Help
Gosub Have_help_key
Else
If Fkey=68 Then ! F10
Gosub Record_is_done
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Endif
Return
'
'
' =============================================================================
' COMPUTE_MOUSE_FIELD: Computes which field the MOUSE was clicked on.
' -----------------------------------------------------------------------------
Procedure Compute_mouse_field
X%=Menu(10)
Y%=Menu(11)-22*Rez%
'
Fld%=0
For I%=1 To Num_flds%
If X%>=Fld_hstart%(I%) And X%<Fld_xstart%(I%)+8*Fld_leng%(I%) Then
If Y%>=Fld_yline%(I%)-7*Rez% And Y%<Fld_yline%(I%)*Rez% Then
Fld%=I%
Endif
Endif
Exit If Fld%>0
Next I%
'
If X%<=Fld_xstart%(Fld%) Then
Nxt_xsub%=1
Else
Nxt_xsub%=Int((X%-Fld_xstart%(Fld%))/8)+1
Endif
'
If Fld%>0 Then
If Fld%=Fld_num% Then
Gosub Cursor
Xsub%=Nxt_xsub%
Gosub Cursor
Else
Nxt_fld%=Fld%
Gosub Next_field
Endif
Endif
Return
'
'
' =============================================================================
' CURSOR: Draws or erases the cursor block.
' -----------------------------------------------------------------------------
Procedure Cursor
Graphmode 3
Deffill 1,1
Xchar%=Xstart%+(Xsub%-1)*8
Pbox Xchar%-1,Yline%+2*Rez%,Xchar%+8,Yline%-8*Rez%
Graphmode 1
Return
'
'
' =============================================================================
' HAVE_DATA: Check if key is valid for this field type.
' -----------------------------------------------------------------------------
Procedure Have_data
C$=Chr$(Menu(14))
If Type_input$="ANY" Then
Gosub Keep_data
Else
If Type_input$="A-Z" Then
If Instr(" .,-ABCDEFGHIJKLMNOPQRSTUVWXYZ",Upper$(C$)) Then
Gosub Keep_data
Else
Gosub Beep
Endif
Else
If Type_input$="NUM" Then
If Instr("0123456789",C$) Then
Gosub Keep_data
Else
Gosub Beep
Endif
Else
If Instr(" ()-0123456789",C$) Then
Gosub Keep_data
Else
Gosub Beep
Endif
Endif
Endif
Endif
Return
'
'
' =============================================================================
' KEEP_DATA: Key is valid, so add it to the field.
' -----------------------------------------------------------------------------
Procedure Keep_data
Gosub Cursor
'
If Insert_mode%=1 Then
L%=Fleng%-Xsub%
If L%>0 Then
Mid$(Temp$,Xsub%+1,L%)=Mid$(Temp$,Xsub%,L%)
Mid$(Temp$,Xsub%,1)=" "
Text Xstart%,Yline%,Temp$
Endif
Endif
'
Text Xchar%,Yline%,C$
Mid$(Temp$,Xsub%,1)=C$
If Xsub%<Fleng% Then
Inc Xsub%
Add Xchar%,8
Endif
Gosub Cursor
Return
'
'
' =============================================================================
' BEEP: Key is not valid, so make a beeping noise.
' -----------------------------------------------------------------------------
Procedure Beep
Sound 1,12,1,8,1
Sound 1,0,0,0
Return
'
'
' =============================================================================
' FINISH_FIELD: Set flag for field done, determine which field is next.
' -----------------------------------------------------------------------------
Procedure Finish_field
Gosub Cursor
'
Fld_done%=1
Nxt_fld%=Fld_num%+1
If Nxt_fld%>Num_flds% Then
Nxt_fld%=1
Endif
Xsub%=1
Return
'
'
' =============================================================================
' NEXT_FIELD: Field may not be done, determine which field is next.
' -----------------------------------------------------------------------------
Procedure Next_field
Gosub Cursor
'
Fld_done%=99
If Nxt_fld%<1 Then
Nxt_fld%=Num_flds%
Else
If Nxt_fld%>Num_flds% Then
Nxt_fld%=1
Endif
Endif
Xsub%=Nxt_xsub%
Return
'
'
' =============================================================================
' HAVE_LEFT_ARROW: Move cursor left but leave data as is.
' -----------------------------------------------------------------------------
Procedure Have_left_arrow
If Xsub%>1 Then
Gosub Cursor
Dec Xsub%
Gosub Cursor
Endif
Return
'
'
' =============================================================================
' HAVE_RIGHT_ARROW: Move cursor right but leave data as is.
' -----------------------------------------------------------------------------
Procedure Have_right_arrow
If Xsub%<Fleng% Then
Gosub Cursor
Inc Xsub%
Gosub Cursor
Endif
Return
'
'
' =============================================================================
' HAVE_BACKSPACE: Move cursor left, pulling data with it.
' -----------------------------------------------------------------------------
Procedure Have_backspace
If Xsub%>1 Then
Gosub Cursor
Dec Xsub%
Gosub Cursor
Gosub Have_delete
Endif
Return
'
'
' =============================================================================
' HAVE_DELETE: Pull data from the right into this position.
' -----------------------------------------------------------------------------
Procedure Have_delete
Gosub Cursor
L%=Fleng%-Xsub%
If L%=0 Then
Mid$(Temp$,Fleng%,1)=" "
Text Xchar%,Yline%," "
Else
Mid$(Temp$,Xsub%,L%)=Mid$(Temp$,Xsub%+1,L%)
Mid$(Temp$,Fleng%,1)=" "
Text Xstart%,Yline%,Temp$
Endif
Gosub Cursor
Return
'
'
' =============================================================================
' HAVE_INSERT: Toggle INSERT mode off and on.
' -----------------------------------------------------------------------------
Procedure Have_insert
If Insert_mode%=0 Then
Insert_mode%=1
Deftext 3,0,0,Txt_size%
Text 488,135*Rez%,"Insert mode: ON "
Else
Insert_mode%=0
Deftext 2,0,0,Txt_size%
Text 488,135*Rez%,"Insert mode: Off"
Endif
Deftext 1,0,0,Txt_size%
Return
'
'
' =============================================================================
' CLEAR_FIELD: Set the current field to spaces.
' -----------------------------------------------------------------------------
Procedure Clear_field
Gosub Cursor
Temp$=Space$(Fleng%)
Xsub%=1
Text Xstart%,Yline%,Temp$
Gosub Cursor
Return
'
'
' =============================================================================
' HAVE_UNDO_KEY: Restore the original value of the current field.
' -----------------------------------------------------------------------------
Procedure Have_undo_key
Gosub Cursor
Temp$=Hold$
Xsub%=1
Text Xstart%,Yline%,Temp$
Gosub Cursor
Return
'
'
' =============================================================================
' HAVE_HELP_KEY: Display the HELP message.
' -----------------------------------------------------------------------------
Procedure Have_help_key
X%=Int((80-Len(Fld_help$(Fld_num%)))/2)
Print At(X%,21);Fld_help$(Fld_num%)
Return
'
'
' =============================================================================
' RECORD_IS_DONE: Set flags to end the input process.
' -----------------------------------------------------------------------------
Procedure Record_is_done
Gosub Cursor
Fld_done%=1
Rec_done%=1
Return
'
' ------------- SAVE ORIGINAL COLOR PALETTE -----------------------
Procedure Save_pal
'
' Requires Dim Spalette%(16,3)
'
For Z%=0 To 15
Dpoke Contrl,26
Dpoke Contrl+2,0
Dpoke Contrl+6,2
Dpoke Intin,Z%
Dpoke Intin+2,0
Vdisys
Spalette%(Z%,0)=Dpeek(Intout+2)
Spalette%(Z%,1)=Dpeek(Intout+4)
Spalette%(Z%,2)=Dpeek(Intout+6)
Next Z%
Return
'
Procedure Restorepal
' --------------------- RESTORES PALLET -------------------
' Dimensions: Spalette%(16,3)
'
For Z%=0 To 15
Dpoke Contrl,14
Dpoke Contrl+2,0
Dpoke Contrl+6,4
Dpoke Intin,Z%
Dpoke Intin+2,Spalette%(Z%,0)
Dpoke Intin+4,Spalette%(Z%,1)
Dpoke Intin+6,Spalette%(Z%,2)
Vdisys
Next Z%
Return
' --------------------------- END OF LISTING 2 ------------------------------